package com.lai.note.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.lai.note.R;
import com.lai.note.dto.ResponseResult;
import com.lai.note.service.UserBaseService;
import com.lai.note.util.RetrofitRequest;
import com.lai.note.util.SHA256Utils;
import com.lai.note.util.ToastUtil;
import com.lai.note.util.UserBaseUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class RegisterActivity extends AppCompatActivity {

    //注册相关信息：手机号，验证码，第一次输入的密码，第二次输入的确认密码
    private EditText et_phone;
    private EditText et_code;
    private EditText et_loginPwd;
    private EditText et_confirmPwd;
    private String phone;
    private String code;
    private String loginPwd;
    private String confirmPwd;

    //获取验证码按钮
    private Button btn_code;
    //注册提交按钮
    private Button btn_register;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
        setListeners();
    }

    private void initView(){
        et_phone = findViewById(R.id.et_userPhone);
        et_code = findViewById(R.id.code);
        et_loginPwd = findViewById(R.id.et_loginPwd);
        et_confirmPwd = findViewById(R.id.et_confirmPwd);
        btn_register = findViewById(R.id.btn_register);
        btn_code = findViewById(R.id.btn_code);

    }

    private void setListeners(){

        btn_code.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phone = et_phone.getText().toString();
                UserBaseUtil.getCode(getApplicationContext(),phone);
            }
        });

        btn_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                phone = et_phone.getText().toString();
                code = et_code.getText().toString();
                loginPwd = et_loginPwd.getText().toString();
                confirmPwd = et_confirmPwd.getText().toString();
                UserBaseUtil.register(getApplicationContext(),phone,code,loginPwd,confirmPwd);
            }
        });
    }





}
